﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="EditMovimentoScaricoSearch.aspx.cs" Inherits="FimetContoDeposito.Operazioni.EditMovimentoScaricoSearch" %>

<%@ Register assembly="GrayParrot.Web.Controls" namespace="GrayParrot.Web.Controls" tagprefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <asp:PlaceHolder ID="PlaceHolder1" runat="server">        
        <%: Scripts.Render("~/bundles/JQuery") %>          
        <%: Scripts.Render("~/bundles/JQueryUI") %>  
        <%: Styles.Render("~/bundles/Formly/css") %>
        <%: Scripts.Render("~/bundles/Formly") %>

        <%: Styles.Render("~/bundles/Datatables/css") %>
        <%: Scripts.Render("~/bundles/Datatables") %>
    </asp:PlaceHolder>

    <!-- Common -->
    <script type="text/javascript" lang="javascript" src="../Scripts/Formly/FormlyHelper.js"></script>
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.Core.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.AngularJS.Directives.Fileupload.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.AngularJS.Directives.DateTimePicker.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.AngularJS.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.DataTables.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.Modals.js"></script> 

    <script type="text/javascript" lang="javascript" src="../Scripts/jquery.blockUI.js"></script> 
    <!-- Common -->
</asp:Content>

<asp:Content ID="ContentSH" ContentPlaceHolderID="specialHead" runat="server">
    <style>
        td { font-size: 11px; padding: 0px; margin:0px; }
        table thead > tr > th, table tbody > tr > th, table tfoot > tr > th, table thead > tr > td, table tbody > tr > td, table tfoot > tr > td {
          border-top: 1px solid #EDEDED;
          padding: 1px 1px;
        }
        .col-xs-4
        {
            padding:2px;
        }
        .col-xs-3
        {
            padding:2px;
        }
        .col-xs-10
        {
            padding:1px;
        }
        .col-xs-12
        {
            padding:1px;
        }
        .form-control
        {
            font-size:14px;
            padding:2px;
        }
    </style>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <!-- 
        Sitemap Menu item:
        <siteMapNode url="~/EditMovimentoCaricoSearch.aspx" title="EditMovimentoCaricoSearch" description="EditMovimentoCaricoSearch" image="fa-laptop" id="EditMovimentoCaricoSearch"/>
    -->
    <section class="panel">
	    <header class="panel-heading">
			<b>Ricerca documenti di scarico</b>
		</header>
		<div class="panel-body">
            <iframe id='iframeCrud' frameborder="0" style="width:600px; height:500px; display:none"></iframe>
            <div id="crudDialog" title="" style="display:none"></div>
            <div id="deleteDiv" title="" style="display:none"></div>

            <!-- PUT YOUR CONTENT HERE -->
            <div class="row" ng-app="formlyExample" ng-controller="MainCtrl as vm" name="divContainer" id="divContainer">
                <div name="divContainerR" id="div2">
                    <div ng-if="vm.loadingData.$$state.status === 0" style="margin:20px 0;font-size:2em">
                        <strong>Caricamento...</strong>
                    </div>
                    <div ng-if="vm.loadingData.$$status.state !== 0">
                        <form ng-submit="vm.onSubmit()" novalidate id="form1">
                            <formly-form model="vm.model" fields="vm.fields" form="vm.form">
                                <button type="sumbit" class="btn btn-primary submit-button" ng-disabled="vm.form.$invalid">Cerca</button>
                            </formly-form>
                        </form>
                    </div>
                </div>
            </div>

            <cc1:JQDataTable ID="JQDTTable" runat="server" 
                    SelectionMode="Single" 
                    RenderScripts="false" 
                    IsResponsive="true"
                    BootstrapClasses="table table-hover table-bordered table-condensed">
                <FeaturesConfig>
                    <Features>
                        <cc1:Searching Value="none" ExternalFilters="true" />
                        <cc1:AutoWitdh Value="true" />
                        <cc1:ScrollY Value="400" ScrollCollapse="true" />
                        <cc1:LengthChange Value="false" />
                        <%--<cc1:Paging PagingType="FullNumbers" PageLength="20" />--%>
                    </Features>
                </FeaturesConfig>
                <ControllerConfig Url="" LoadingMode="Manual" />
                <ColumnsConfig Key="Id">
                    <Columns>
                        <cc1:TextColumn Name="Id" Header="Id" visible="false" />
                        <cc1:TextColumn Name="DataMovimento" Header="Data Mov."/>
                        <cc1:TextColumn Name="Customer" Header="Magazzino" />
                        <cc1:TextColumn Name="Fornitore" Header="Fornitore" />
                        <cc1:TextColumn Name="IdDocumento" Header="Tipo Doc." Visible="false" />
                        <cc1:TextColumn Name="TipoDocumento" Header="Tipo Doc." />
                        <cc1:TextColumn Name="NumeroDocumento" Header="Num.Doc." />
                        <cc1:DateColumn Name="DataDocumento" Header="Data Doc." />
                        <cc1:BooleanColumn Name="Chiuso" Header="Chiuso" />
                        <cc1:BooleanColumn Name="Cancellato" Header="Cancellato" />
                        <cc1:ActionColumn >
                            <Actions>
                                <cc1:ActionIcon Icon="fa fa-edit" Callback="ModificaMovimento" />
                                <cc1:ActionIcon Icon="fa fa-book" Callback="ModificaDocumento" />
                            </Actions>
                        </cc1:ActionColumn>
                    </Columns>
                </ColumnsConfig>
            </cc1:JQDataTable>            
		</div>
	</section>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="LocaJavascript" runat="server">
    <% HttpContext.Current.Response.Write(this.JQDTTable.RenderScriptsManually()); %>
<script>
    var settings = new FormlySettings();
    settings.container = '#divContainer';
    settings.shortcutCallback = DoSubmit;
    settings.setLoad(settings.createGetConfig('/api/Movimenti/LoadFieldsEditMovimentoScaricoSearch'));
    FormlyManager(settings);

    function DoSubmit() {
        var model = extScope.vm.model;

        var url = '/api/Movimenti/GetMovimentiScaricoToEdit';

        var m_dataMovimento = $('#formly_1_grayParrotDateTimePicker_DataMovimento_0').val();
        var m_dataDocumento = $('#formly_1_grayParrotDateTimePicker_DataDocumento_5').val();
        var m_data = JSON.stringify({ data: model, dataMov: m_dataMovimento, dataDoc: m_dataDocumento });

        $.ajax({
            type: "POST",
            url: url,
            data: m_data,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {

                if (response == null) {
                    alert("Nessun movimento trovato.");
                } else {
                    $.each(response, function (index, value) {
                        AggiungiElementoTabella(value);
                    });
                }

            },
            failure: function (response) {
                alert(response);
            }
        });
    }

    function AggiungiElementoTabella(obj) {
        var m_caricoItem = new Object();
        m_caricoItem.Id = obj.Id;
        m_caricoItem.DataMovimento = obj.DataMovimento;
        m_caricoItem.Customer = obj.Customer;
        m_caricoItem.Fornitore = obj.Fornitore;
        m_caricoItem.IdDocumento = obj.IdDocumento;
        m_caricoItem.TipoDocumento = obj.TipoDocumento;
        m_caricoItem.NumeroDocumento = obj.NumeroDocumento;
        m_caricoItem.DataDocumento = obj.DataDocumento;
        m_caricoItem.Chiuso = obj.Chiuso;
        m_caricoItem.Cancellato = obj.Cancellato;

        m_tableJQDTTable.row.add(m_caricoItem).draw();
    }

    function CloseDialog(response) {
        $('#crudDialog').dialog('close');

        alert(response);
    }

    function ModificaMovimento(obj) {
        var p = obj.Id;

        window.location.replace('/Operazioni/MovimentoScarico.aspx?Id=' + p)
    }

    function ModificaDocumento(obj) {
        var p = null;
        p = obj.IdDocumento;

        var url = '/Operazioni/AnagraficaDocumenti_CRUD.aspx?id=' + p;

        $("#iframeCrud").prop('src', url).appendTo("#crudDialog");
        $("#iframeCrud").show();

        m_dialog = $("#crudDialog").dialog({
            title: 'Articolo',
            width: 'auto',
            height: 'auto',
            modal: true,
            close: function (response) {
                Empty(m_tableJQDTTable);
                DoSubmit();

                $("#iframeCrud").contents().remove();
                $('#iframeCrud').hide();
            }
        });
    }
</script>
</asp:Content>